package Greedy_Snake_Map;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

import Greedy_Snake_Map.Map_Type.Type;
import snake.Snake_body;

public class MMap{
	public static BufferedImage fillimagewall;//墙的绘画格式
	public static BufferedImage fillapple,fillbanana,fillwaterm_;
	public static int food_much;//地图上食物的数量
	public static double food_scale=0.03;//食物的比例占所有格子的比例
	private static int x=300;//数组的纵
	private static int y=300;//数组的横
	public static Map_Type[][] attribute;//地图数组属性
	private static MMap map=new MMap();
	private void set_bufferedimage()
	{
		try {
			
			fillimagewall=ImageIO.read(new File("img\\wall.png"));
			fillapple=ImageIO.read(new File("img\\apple.png"));
			fillbanana=ImageIO.read(new File("img\\banana.jpg"));
			fillwaterm_=ImageIO.read(new File("img\\watermelon.jpg"));
		}catch(Exception e){
			e.getStackTrace();
		}
	}
	
	private MMap()
	{
		Init();
		set_bufferedimage();
	}
	public static MMap getMMap()//工厂map
	{
		return map;
	}
	public static void random_Food()
	{
		double kind;
		int tx,ty;
		while(food_much<(get_x()*get_y()*food_scale))
		{
			
			kind=Math.random();
			tx=((int)(Math.random()*10000))%get_x();
			ty=((int)(Math.random()*10000))%get_y();
			
			if(attribute[tx][ty].value!=0) continue;
			food_much++;
			if(kind>0.9)
			{
				attribute[tx][ty].type=Type.banana;
				attribute[tx][ty].value=10;
			}else if(kind>0.7)
			{
				attribute[tx][ty].type=Type.apple;
				attribute[tx][ty].value=-4;
			}else 
			{
				attribute[tx][ty].type=Type.watermelon;
				attribute[tx][ty].value=2;
			}
		}
	}
	public void Init()
	{
		attribute=new Map_Type[x][y];
		for(int x=0;x<attribute.length;x++) for(int y=0;y<attribute[x].length;y++)
			attribute[x][y]=new Map_Type();
	}
	public static  int get_x()
	{
		return x;
	}
	public static int get_y()
	{
		return y;
	}
}

